{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "import json\n",
    "import os\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "jsonpath = './twitter16_kfold_results/'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "def getscores(jsonpath,file):\n",
    "    results = []\n",
    "    with open(jsonpath+file,'r') as f:\n",
    "        resultjsons = f.readlines()\n",
    "        results = [json.loads(x.strip()) for x in resultjsons] \n",
    "\n",
    "    acc = []\n",
    "    f10 = []\n",
    "    f11 = []\n",
    "    f12 = []\n",
    "    f13 = []\n",
    "    model = ''\n",
    "\n",
    "    for result in results:\n",
    "#         print(result)\n",
    "        model = file\n",
    "        if 'acc' in result:\n",
    "            acc.append(result['acc'])\n",
    "        if 'Acc' in result:\n",
    "            acc.append(result['Acc'])\n",
    "        \n",
    "        f10.append(result['0']['f1-score'])\n",
    "        f11.append(result['1']['f1-score'])\n",
    "        f12.append(result['2']['f1-score'])\n",
    "        f13.append(result['3']['f1-score'])\n",
    "\n",
    "    acc = (np.mean(acc), np.std(acc))\n",
    "    f10 = (np.mean(f10), np.std(f10))\n",
    "    f11 = (np.mean(f11), np.std(f11))\n",
    "    f12 = (np.mean(f12), np.std(f12))\n",
    "    f13 = (np.mean(f13), np.std(f13))\n",
    "    \n",
    "    return model,acc,f10,f11,f12,f13"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('lstmwithAttention.json', (0.6307867049258729, 0.009579757257716153), (0.71370973294663, 0.033451571932421695), (0.5000063019815005, 0.29162719710337925), (0.6500043514833344, 0.03381207037081224), (0.5321065837965886, 0.038334861547968516))\n",
      "('BilstmwithAttention.json', (0.6210246293639408, 0.02094423582781224), (0.7169813973878592, 0.018458756118583507), (0.49704861217730234, 0.28832928059960067), (0.642185034049865, 0.04045938066704037), (0.5204111391889272, 0.06486160805590495))\n",
      "('gruwithAttention.json', (0.6185796269727404, 0.02452515528622801), (0.7019221560677358, 0.04389625578778846), (0.5105410914812961, 0.29476823316749057), (0.6309399386845039, 0.019256714819296684), (0.510531694341763, 0.03462408215173182))\n",
      "('lstm.json', (0.6528156384505022, 0.0056851606272297715), (0.7350585801696565, 0.025368347347647206), (0.5168895617105943, 0.29968438678359566), (0.6803620268549768, 0.0402538670379931), (0.5127430309559637, 0.041861009681490605))\n",
      "('Bilstm.json', (0.6038677666188427, 0.01888874534955635), (0.7447818864654052, 0.024362421113245335), (0.48151743976986694, 0.28236769525871286), (0.6017733112053598, 0.02903502462803182), (0.4479323308270676, 0.03746736194389867))\n",
      "('gru.json', (0.6332137733142037, 0.027055468118145725), (0.7085550360757433, 0.047852484146825226), (0.5119030471800781, 0.30053961759497744), (0.68696191075785, 0.007996693526628074), (0.47228311328148553, 0.061566870655429456))\n",
      "('BigruwithAttention.json', (0.5426948828311813, 0.05412636564810808), (0.6179384944011802, 0.03877384459983254), (0.4992788755425149, 0.28974620554070607), (0.5486122448979591, 0.04181638131090724), (0.4003423434150988, 0.015899454532662522))\n",
      "('bertTextEnc.json', (0.774390243902439, 0.039157547214639814), (0.8992398696832238, 0.02635169023659087), (0.5552655571077412, 0.32410333952378073), (0.7383136339060434, 0.03981813796014733), (0.7277515905147485, 0.07484822209360081))\n",
      "('Bigru.json', (0.623493543758967, 0.03974729454986035), (0.7324915110356536, 0.06184650034546913), (0.5145654454297454, 0.2971435778046564), (0.6329594947735192, 0.07631165713153548), (0.450782096594035, 0.03958310244067676))\n"
     ]
    }
   ],
   "source": [
    "jsons = []\n",
    "\n",
    "for fname in os.listdir(jsonpath):\n",
    "    if fname.endswith('.json'):\n",
    "        jsons.append(fname)\n",
    "\n",
    "for file in jsons:    \n",
    "    print(getscores(jsonpath,file))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "fakenews",
   "language": "python",
   "name": "fakenews"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
